<?php
/**
 * Created by PhpStorm.
 * User: Soha_Ros
 * Date: 17/5/26
 * Time: 下午4:00
 *
 * 更新商品分类
 *
 */

namespace ActionsHttp;


use Data\Food_groups_DAO;

class RestaurantFoodGroupsUpdate extends BaseActionHttp
{
    public function doAction() {
        parent::doAction();

        // 商铺id
        $restaurant_id = $_SESSION[RESTAURANT_ID];
        $restaurant_id = 1;

        // 分类ID
        $group_id = $this->data[FOOD_GROUP_ID];

        // 分类名称
        $name = $this->data[FOOD_GROUP_NAME];
        // 分类描述
        $description = $this->data[DESCRIPTION];

        // 新建分类
        $food_groups_record = Food_groups_DAO::getRecord($group_id);

        if (!$food_groups_record) {
            return $this->SendErrMsg("没有该分类");
        }

        if ($food_groups_record->getRESTAURANT_ID() != $restaurant_id) {
            return $this->SendErrMsg("非法操作");
        }

        $food_groups_record->setFOOD_GROUP_NAME($name);
        $food_groups_record->setDESCRIPTION($description);

        // 插入数据库
        Food_groups_DAO::update($food_groups_record);

        // 返回数据
        $this->ResponseDataToCurrentClient();
    }
}